<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_invitation_list',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$v){
		$v['createtime']=date('Y/m/d H:i:s',$v['createtime']);
		$v['url']=custom_url('jy_invitation/index/detail/id='.$v['id'],true);
		$v['url1']=array('action'=>'post','plugin'=>'jy_invitation','query'=>'id='.$v['id']);
		if($v['data']){
			$date=json_decode($v['data'],true);
			$v['picsnum']=count($date);
			foreach($date as $img){
				$v['image']= $img;
			}
			
		}
	}
	$return['list']=$list?$list:array();
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误','error');
	}
	$in=pdo_get('jy_invitation_list',array('id'=>$id));
	$m=pdo_get('core_fans',array('openid'=>$_SESSION['openid']));
	$member['nickname']=$m['nickname'];
	$member['avatar']=$m['avatar'];
	if($in['data']){
		$data=json_decode($in['data'],true);
		foreach($data as $k=>$v){
			$url=custom_url('jy_weishop/index//fromuser='.$_SESSION['mid'],true);
			$qr=cfc('tools')->createqrcode($url,150,true);
			//$post=array('bg'=>'addons/jy_invitation/templist/image_'.$v.'_bg.jpg','id'=>$in['id'].'+'.$v,'text1'=>$in['text1'],'text2'=>$in['text2'],'text3'=>$in['text3']);
			$v=str_replace('_nail','_bg',$v);
			$post=array('bg'=>tomedia($v),'id'=>$in['id'],'k'=>$k,'text1'=>$in['text1'],'text2'=>$in['text2'],'text3'=>$in['text3'],'text4'=>$in['text4'],'text5'=>$in['text5']);
			$img=$this->createPoster($post,$qr,$member);			
			$return['list'][]=array('bg'=>$img);
			
		}
	}
	exi($return);
}